    /**
     * Created by Liu Shijie
     * 2017.6.18
     */

    //登录：密码和用户名匹配
    function Login() {
        var xmlhttp;
        var user = document.getElementById("userid").value;
        var psd = document.getElementById("userpsd").value;

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                if (xmlhttp.responseText == "wrong") {
                    alert("密码错误！");
                } else if (xmlhttp.responseText == "unregistered") {
                    alert("该账号尚未注册！");
                } else if (xmlhttp.responseText == "fail") {
                    alert("数据库查询失败！");
                } else {
                    self.location = "http://mtuchn.cn/wysy/index.php";
                }
            }
        }
        xmlhttp.open("GET", "server/login_verify.php?user=" + user + "&psd=" + psd, true);
        xmlhttp.send();
    }

    //验证是否登陆
    function Login_Judge() {
        var xmlhttp;
        var node = document.getElementById("user_state");

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                if (xmlhttp.responseText != 0) {
                    document.getElementById("myAccount").innerHTML = xmlhttp.responseText;
                    node.innerHTML = "退 出";
                    node.setAttribute("href", "#");
                } else {
                    document.getElementById("myAccount").innerHTML = "用户名";
                }
            }
        }

        xmlhttp.open("GET", "server/login_judge.php", true);
        xmlhttp.send();
    }
    window.onload = Login_Judge;

    // 退出时清理cookies
    function user_quiz() {
        var xmlhttp;

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var node = document.getElementById("user_state");
                node.innerHTML = "登 录";
                node.setAttribute("href", "login.php");
                document.getElementById("myAccount").innerHTML = "用户名";
            }
        }
        xmlhttp.open("GET", "server/quit_login.php", true);
        xmlhttp.send();
    }


    //商品详情页面加入购物车

    function addToCart_1() {

        var img_node = document.getElementsByName("goods_pic")[0];
        var id = img_node.getAttribute("id");  //图书id
        var num = document.getElementsByName("goods_num")[0].value;

        var xmlhttp;

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                if (xmlhttp.responseText == 1) {
                    alert("成功添加进购物车！");
                } else if (xmlhttp.responseText == 0) {
                    alert("操作失败！");
                } else if (xmlhttp.responseText == 2) {
                    alert("请先登陆！");
                } else {
                    alert("Wrong!");
                }
            }
        }
        xmlhttp.open("GET", "server/AddCart.php?id=" + id + "&num=" + num, true);
        xmlhttp.send();
    }


    /**
     * 单击购物车按钮，添加至购物车
     */
    function addToCart_btn(node) {

        var id = node.getAttribute("id");  //图书id
        var num = 1;

        var xmlhttp;

        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                if (xmlhttp.responseText == 1) {
                    alert("成功添加进购物车！");
                } else if (xmlhttp.responseText == 0) {
                    alert("操作失败！");
                } else if (xmlhttp.responseText == 2) {
                    alert("请先登陆！");
                } else {
                    alert("Wrong!");
                }
            }
        }
        xmlhttp.open("GET", "server/AddCart.php?id=" + id + "&num=" + num, true);
        xmlhttp.send();
    }

